<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>考勤异常说明</title>
    <style>
        /* 基础样式 */
        body {
            font-family: "Microsoft YaHei", SimSun, sans-serif;
            margin: 0;
            padding: 0;
            line-height: 1.6;
            background-color: #f9f9f9;
            color: #333;
        }
        
        .container {
            width: 21cm;
            padding: 1.5cm;
            margin: 20px auto;
            box-sizing: border-box;
            background-color: #fff;
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
            border-radius: 8px;
        }
        
        .header {
            text-align: center;
            margin-bottom: 30px;
            padding-bottom: 15px;
            border-bottom: 2px solid #667eea;
        }
        
        .report-title {
            font-size: 28px;
            font-weight: bold;
            color: #667eea;
            margin: 0;
            letter-spacing: 1px;
        }
        
        .employee-info {
            font-size: 16px;
            margin-bottom: 25px;
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 15px;
        }
        
        .employee-info span {
            padding: 8px 12px;
            border: 1px solid #e0e0e0;
            border-radius: 4px;
            background-color: #f5f9ff;
        }
        
        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 30px;
            font-size: 14px;
        }
        
        th, td {
            padding: 12px 15px;
            text-align: center;
            border: 1px solid #e0e0e0;
        }
        
        th {
            background-color: #f0f7ff;
            font-weight: bold;
            color: #2c3e50;
        }
        
        .editable {
            min-height: 20px;
            outline: none;
            display: block;
            padding: 5px;
            transition: all 0.2s ease;
        }
        
        .editable:focus {
            background-color: #f5f9ff;
            border-radius: 3px;
        }
        
        .signature-container {
            margin-top: 50px;
        }
        
        .signature-area {
            display: flex;
            justify-content: space-between;
            margin-top: 40px;
        }
        
        .signature-box {
            width: 45%;
            position: relative;
        }
        
        .signature-field {
            height: 60px;
            border-bottom: 1px solid #667eea;
            margin-bottom: 20px;
            position: relative;
        }
        
        .signature-info {
            display: flex;
            justify-content: space-between;
        }
        
        .signature-date {
            width: 100%;
            text-align: center;
        }
        
        .date-input {
            display: inline-block;
            width: 40px;
            border-bottom: 1px solid #667eea;
            text-align: center;
            margin: 0 5px;
        }
        
        .note {
            margin-top: 30px;
            font-size: 13px;
            color: #666;
            padding: 15px;
            background-color: #f5f9ff;
            border-radius: 5px;
        }
        
        .controls {
            position: fixed;
            right: 30px;
            top: 50%;
            transform: translateY(-50%);
            display: flex;
            flex-direction: column;
            gap: 12px;
            z-index: 100;
        }
        
        button {
            padding: 10px 20px;
            cursor: pointer;
            border: none;
            border-radius: 25px;
            color: white;
            font-weight: bold;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
            font-size: 14px;
            display: flex;
            align-items: center;
            gap: 8px;
            min-width: 120px;
            justify-content: center;
        }
        
        button:hover {
            background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
            box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
            transform: translateY(-2px);
        }
        
        .reason-box {
            margin: 20px 0;
            padding: 15px;
            border: 1px solid #e0e0e0;
            border-radius: 5px;
            background-color: #f5f9ff;
        }
        
        .reason-title {
            font-weight: bold;
            margin-bottom: 10px;
            color: #667eea;
        }
        
        @media print {
            .no-print {
                display: none;
            }
            body {
                background: none;
            }
            .container {
                padding: 0;
                width: auto;
                margin: 20px;
                box-shadow: none;
            }
            button {
                display: none;
            }
            .report-title {
                font-size: 24px;
            }
        }
    </style>
</head>
<body>
    <div class="controls no-print">
        <button onclick="addRow()"><i class="fa fa-plus"></i> 增加记录</button>
        <button onclick="removeRow()"><i class="fa fa-minus"></i> 删除记录</button>
        <button onclick="window.print()"><i class="fa fa-print"></i> 打印</button>
    </div>
    
    <div class="container">
        <div class="header">
            <div class="report-title">考勤异常情况说明</div>
        </div>
        
        <div class="employee-info">
            <div>姓名：<span class="editable" id="employee-name" contenteditable="true"></span></div>
            <div>电话：<span class="editable" id="employee-phone" contenteditable="true"></span></div>
        </div>
        
        <div class="reason-box">
            <div class="reason-title">异常情况说明：</div>
            <div class="editable" contenteditable="true" style="min-height: 80px; line-height: 1.6;">
                请简要说明考勤异常原因（如病假、事假、出差、交通延误等特殊情况）
            </div>
        </div>
        
        <table id="attendance-table">
            <thead>
                <tr>
                    <th width="10%">序号</th>
                    <th width="20%">异常日期</th>
                    <th width="20%">异常类型</th>
                    <th width="20%">实际时间</th>
                    <th width="30%">备注</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>1</td>
                    <td><div class="editable" contenteditable="true">2023-XX-XX</div></td>
                    <td><div class="editable" contenteditable="true">迟到/早退/缺勤</div></td>
                    <td><div class="editable" contenteditable="true">09:30</div></td>
                    <td><div class="editable" contenteditable="true"></div></td>
                </tr>
                <tr>
                    <td>2</td>
                    <td><div class="editable" contenteditable="true">2023-XX-XX</div></td>
                    <td><div class="editable" contenteditable="true">迟到/早退/缺勤</div></td>
                    <td><div class="editable" contenteditable="true">09:30</div></td>
                    <td><div class="editable" contenteditable="true"></div></td>
                </tr>
            </tbody>
        </table>
        
        <div class="signature-container">
            <div class="signature-area">
                <div class="signature-box">
                    <div class="signature-field">申请人（签字）</div>
                    <div class="signature-info">
                        <div class="signature-date">
                            日期：
                            <span class="date-input editable" contenteditable="true"></span>年
                            <span class="date-input editable" contenteditable="true"></span>月
                            <span class="date-input editable" contenteditable="true"></span>日
                        </div>
                    </div>
                </div>
                
                <div class="signature-box">
                    <div class="signature-field">证明人（签字）</div>
                    <div class="signature-info">
                        <div class="signature-date">
                            日期：
                            <span class="date-input editable" contenteditable="true"></span>年
                            <span class="date-input editable" contenteditable="true"></span>月
                            <span class="date-input editable" contenteditable="true"></span>日
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="note">
            <strong>注：</strong>
            <ol>
                <li>请如实填写异常情况，并在3个工作日内提交；</li>
                <li>异常类型包括：迟到、早退、缺勤、外出等；</li>
                <li>日期格式：YYYY-MM-DD，时间格式：HH:MM；</li>
                <li>如有其他证明材料，请附在本表后面。</li>
            </ol>
        </div>
    </div>

    <script>
        // 增加行
        function addRow() {
            const table = document.querySelector('#attendance-table tbody');
            const rowCount = table.rows.length + 1;
            const newRow = table.insertRow();
            
            newRow.innerHTML = `
                <td>${rowCount}</td>
                <td><div class="editable" contenteditable="true">2023-XX-XX</div></td>
                <td><div class="editable" contenteditable="true">迟到/早退/缺勤</div></td>
                <td><div class="editable" contenteditable="true">09:30</div></td>
                <td><div class="editable" contenteditable="true"></div></td>
            `;
        }
        
        // 删除行
        function removeRow() {
            const table = document.querySelector('#attendance-table tbody');
            if (table.rows.length > 1) {
                table.deleteRow(table.rows.length - 1);
                // 重新编号
                const rows = table.querySelectorAll('tr');
                rows.forEach((row, index) => {
                    row.cells[0].textContent = index + 1;
                });
            } else {
                alert("至少保留一行记录！");
            }
        }
        
        // 初始化
        document.addEventListener('DOMContentLoaded', function() {
            // 自动调整表格高度
            document.querySelectorAll('.editable').forEach(el => {
                el.style.minHeight = '20px';
            });
            
            // 为日期和时间单元格添加输入验证
            document.addEventListener('input', function(e) {
                const cell = e.target;
                if (cell.parentElement.cellIndex === 1) { // 日期列
                    const value = cell.textContent.trim();
                    if (value && !/^\d{4}-\d{2}-\d{2}$/.test(value)) {
                        cell.textContent = value.replace(/[^\d-]/g, '');
                        // 移动光标到末尾
                        const range = document.createRange();
                        const selection = window.getSelection();
                        range.selectNodeContents(cell);
                        range.collapse(false);
                        selection.removeAllRanges();
                        selection.addRange(range);
                    }
                } else if (cell.parentElement.cellIndex === 3) { // 时间列
                    const value = cell.textContent.trim();
                    if (value && !/^\d{2}:\d{2}$/.test(value)) {
                        cell.textContent = value.replace(/[^\d:]/g, '');
                        // 移动光标到末尾
                        const range = document.createRange();
                        const selection = window.getSelection();
                        range.selectNodeContents(cell);
                        range.collapse(false);
                        selection.removeAllRanges();
                        selection.addRange(range);
                    }
                } else if (cell.classList.contains('date-input')) {
                    const value = cell.textContent.trim();
                    if (value && !/^\d{0,4}$/.test(value)) {
                        cell.textContent = value.replace(/[^\d]/g, '');
                        // 移动光标到末尾
                        const range = document.createRange();
                        const selection = window.getSelection();
                        range.selectNodeContents(cell);
                        range.collapse(false);
                        selection.removeAllRanges();
                        selection.addRange(range);
                    }
                }
            });
        });
    </script>
</body>
</html>